package org.example.xuleihuaiol;

import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        //定义序列话对象
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("E:/IDEA-file/student.java"));
        Student stu = new Student();
        stu.setId(1101);
        stu.setName("紫霞");
        stu.setAge(18);
        //写出对象
        oos.writeObject(stu);
        oos.flush();
        oos.close();
        //反序列化
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("E:/IDEA-file/student.java"));
        Object o = (Student) ois.readObject();
        System.out.println("读取对象数据：" + o);

    }
}
